﻿// cvTrans.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "Calibration.h"
#include "Task.h"
#include "pyscript.h"
#include "uv.h"
#include "util.h"
#include "easylog.h"
//#include "easymqproducer.h"
#include "mqclient.h"
#include <iostream>
#include <ctype.h>

using namespace std;
using namespace util;

list<FramePic>   g_framePics;
uv_mutex_t       g_framePicLock;
//CEasyMqProducer  g_MqCar;
MqClient::CMQProducer  *g_MqProducer;

int main(int argc, char* argv[])
{
	if (argc == 2) {
		// 相机标定
		Log::open(Log::Print::both, uvLogPlus::Level::Debug, "./log/calibrat/log.txt", true);
		Calibration cal;
		cal.m_strImgDir = argv[1];
		cal.run();
		return 0;
	}

	Log::open(Log::Print::both, uvLogPlus::Level::Debug, "./log/trans/log.txt");
	Settings::loadFromProfile("./config.txt");

	//python环境加载
	if (PyScript::Init() != 0) {
		Sleep(3000);
		return 0;
	}

	//mq
	//g_MqCar.load("CarMq");
	string host = Settings::getValue("CarMq", "host");
	int port = Settings::getValue("CarMq", "port", 5672);
	string usr = Settings::getValue("CarMq", "usr");
	string pwd = Settings::getValue("CarMq", "pwd");
	string exc = Settings::getValue("CarMq", "exc", "");
	string type = Settings::getValue("CarMq", "type", "fanout");
	string rout = Settings::getValue("CarMq", "rout", "");
	g_MqProducer = MqClient::CMQProducer::Create("CarMq", host, port, usr, pwd, exc, type, rout);
	Log::debug("mq producer CarMq --> %s %d %s %s %s", host.c_str(), port, usr.c_str(), pwd.c_str(), exc.c_str());
	

	//加载任务
	int tasks = Settings::getValue("Conf", "tasks", 0);
	Log::debug("task count: %d", tasks);
	for (int i = 0; i < tasks; i++) {
		Task *t = new Task(i+1);
		t->run();
	}

	Sleep(INFINITE);
}